const router = require('koa-router')();

router.prefix('/api/v1/products');
router.get('/', function (ctx, next) {
  ctx.body = 'this is a getLowestOfferListings response!'
});

router.get('/matching/:marketplaceid', async (ctx, next) => {
  const sellerId = ctx.headers.sellerid;
  const mwsAuthToken = ctx.headers.mwsauthtoken;
  const marketplaceid = ctx.params.marketplaceid;
  const query = ctx.query.q;

  try {
    let json = await listMatchingProducts.listMatchingProducts(sellerId, mwsAuthToken, marketplaceid, query);
    ctx.response.status = 200;
    ctx.response.body = {
      data: json,
    };
  } catch (error) {
    ctx.response.status = 500;
    ctx.response.body = {
      data: error,
    };
  }
});

module.exports = router;